public class p1019_2_timeout {

	static//
	// -----
	// -----
	public class Main {
		public static void main(String[] args) throws Exception {
			java.util.Scanner in = new java.util.Scanner(System.in);
			int n = in.nextInt();

			java.util.List<Integer> nums = new java.util.ArrayList<Integer>(n);
			for (int i = 0; i < n; i++)
				nums.add(in.nextInt() - 1);

			java.util.Map<Integer, Integer> result = getDigit(new java.util.ArrayList<Integer>(nums));
			for (int num : nums)
				System.out.println(result.get(num));
		}

		// get from: 1 12 123 ... | i from 0
		static java.util.Map<Integer, Integer> getDigit(java.util.List<Integer> nums) {
			java.util.Map<Integer, Integer> map = new java.util.HashMap<Integer, Integer>();
			java.util.Collections.sort(nums);
			int skipped = 0, secLength = 1, lastNum = 1, numLength = 1, nextExpendNumber = 10;
			for (int num : nums) {
				while (num >= skipped + secLength) {
					skipped += secLength;
					lastNum++;
					if (lastNum == nextExpendNumber) {
						numLength++;
						nextExpendNumber *= 10;
					}
					secLength += numLength;
				}
				map.put(num, getDigit2(num - skipped));
			}
			return map;
		}

		// get from: 1234... | i from 0
		static int getDigit2(int i) {
			int secLength = 9, numLength = 1, maxNum = 9, lastMaxNum = 0;
			while (i >= secLength) {
				i -= secLength;
				numLength++;
				lastMaxNum = maxNum;
				maxNum = maxNum * 10 + 9;
				secLength = (maxNum - lastMaxNum) * numLength;
			}

			int num = lastMaxNum + 1 + i / numLength;
			num /= Math.pow(10, numLength - 1 - i % numLength);
			return num % 10;
		}
	}

	// -----
	// -----

	public static void main(String[] args) throws Exception {
		Judge.run("p1019.more.txt");
	}

}
